//
//  ViewController.m
//  SchoolTask
//
//  Created by feel on 16/8/24.
//  Copyright © 2016年 sm. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self post];

}

-(void)post
{

//http://www.100xsys.com.cn/school/app/ajax_wifiLocationStudyInfo/add

    //创建会话对象
    NSURLSession *session = [NSURLSession sharedSession];
    
    
    //根据会话对象创建task
//    NSURL *url = [NSURL URLWithString:@"http://www.100xsys.com.cn/school/app/classroomInfo/listJson"];
    
    NSURL *url = [NSURL URLWithString:@"http://www.100xsys.com.cn/school/app/ajax_wifiLocationStudyInfo/add"];
    
    //创建可变的请求对象
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    
    //修改请求方法为POST
    request.HTTPMethod = @"POST";
    
    //设置请求体
//    request.HTTPBody = [@"appWebconfigId=1&page=1&page=10" dataUsingEncoding:NSUTF8StringEncoding];
    
    //设置请求体
//        NSString *param=[NSString stringWithFormat:@"username=%@&pwd=%@",];
    //把拼接后的字符串转换为data，设置请求体
//        request.HTTPBody=[param dataUsingEncoding:NSUTF8StringEncoding];

    //根据会话对象创建一个Task(发送请求）
        NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
        
        //8.解析数据
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        NSLog(@"%@",dict);
        
    }];
    
    //7.执行任务
    [dataTask resume];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
